723B - Text Document Analysis - CodeForces Solution


expression parsing implementation strings *1100

Please click on ads to support us..

Python Code:

_len=int(input())
_str=input().replace('(',')!').split(')')
_str=list(filter(None,_str))
mxLen,wordsNum=0,0
for word in _str:
    if word[0]=='!':
        words=word[1:].split('_')
        words=list(filter(None,words))
        wordsNum+=len(words)
    else:
        words=word.split('_')
        mxLen=max(mxLen,len(max(words,key=len)))
print(mxLen,wordsNum)

C++ Code:

#include <bits/stdc++.h>
using ll = long long;
#define Shalaby ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
#define endl '\n'
#define Endl '\n'
#define nl cout << '\n'
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
bool y_n(bool t)
{
    cout << ((t) ? "YES\n" : "NO\n");
}
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string c = "";
    int ans = 0, cntr = 0;
    bool check = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(')
        {
          //  cout << c << endl;
            ans = max(ans, int(c.size()));
            c = "";
            check = 1;
            continue;
        }
        else if (s[i] == ')')
        {
            if (c != "")
                cntr++;
            check = 0;
            c = "";
            continue;
        }
        if (check)
        {
            if (s[i] != '_')
                c += s[i];
            else
            {
               // cout << c << endl;
                if (c != "")
                {
                    cntr++;
                }
                c = "";
            }
        }
        else
        {
            if (s[i] != '_')
                c += s[i];
            else
            {
                //cout << c << endl;
                ans = max(ans, int(c.size()));
                c = "";
            }
        }
    }
   // cout << c << endl;
    ans = max(ans , int(c.size()));
    cout << ans << ' ' << cntr << endl;
}
int main()
{
    Shalaby;
    //    freopen("mex.in", "rt", stdin);
    int n = 1;
    // cin >> n;
    while (n--)
    {
        solve();
    }
}
/*

*/


Comments

Submit
0 Comments
More Questions

1702C - Train and Queries
816B - Karen and Coffee
838D - Airplane Arrangements
148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality
610A - Pasha and Stick
1200A - Hotelier
1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves